// Copyright (c) 2019 Presto Labs Pte. Ltd.
// Author: xguo

#pragma once

#include <optional>
#include <string>

#include "coin/proto/coin_market_enums.pb.h"

namespace coin2::exchange::base::market {

using MarketType = coin::proto::MarketType;
using ExchangeType = coin::proto::ExchangeType;

inline const std::string& ExchangeTypeToString(const coin::proto::ExchangeType exchange) {
  return ExchangeType_Name(exchange);
}

inline std::optional<ExchangeType> StringToExchangeType(const std::string& exchange_str) {
  ExchangeType exchange;
  bool success = coin::proto::ExchangeType_Parse(exchange_str, &exchange);
  if (success) {
    return exchange;
  } else {
    return {};
  }
}

inline const std::string& MarketTypeToString(const coin::proto::MarketType market) {
  return MarketType_Name(market);
}

inline std::optional<MarketType> StringToMarketType(const std::string& market_type_str) {
  MarketType market_type;
  bool success = coin::proto::MarketType_Parse(market_type_str, &market_type);
  if (success) {
    return market_type;
  } else {
    return {};
  }
}

}  // namespace coin2::exchange::base::market
